﻿package mortal.game.view.heroArena.view
{
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class HeroArenaIcon extends ActionBaseIcon
    {
        protected var _leftTime:SecTimerView;
        private static var _instance:HeroArenaIcon;

        public function HeroArenaIcon(param1:ExceptionClass)
        {
            super(ResFileConst.HeroArenaIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftTime = UIFactory.secTimeView("mm:ss", 5, 50, 48, 20, this, GlobalStyle.textFormatHong.center());
            this._leftTime.visible = false;
            this._leftTime.timeOutHandler = this.timeCompl;
            return;
        }// end function

        public function timeCompl() : void
        {
            if (this._leftTime)
            {
                this._leftTime.stop();
                this._leftTime.visible = false;
            }
            return;
        }// end function

        public function updateOpenDt(param1:Date) : void
        {
            var _loc_2:* = (param1.time - ClockManager.instance.nowDate.time) / 1000;
            if (this._leftTime && _loc_2 > 0)
            {
                this._leftTime.visible = true;
                this._leftTime.setLeftTime(_loc_2);
            }
            return;
        }// end function

        public function updateLeftTime(param1:int) : void
        {
            if (param1 > 0 && this._leftTime)
            {
                this._leftTime.visible = true;
                this._leftTime.setLeftTime(param1);
            }
            return;
        }// end function

        public function isLeftTimeVisible() : Boolean
        {
            if (this._leftTime)
            {
                return this._leftTime.visible;
            }
            return false;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            if (GameController.copy.heroArenaCopy.isArenaOpen && !GameController.copy.heroArenaCopy.isArenaBegin)
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(41547, currentTimeStr), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (GameMapUtil.curMapState.isHeroArenaRestRoomMap || GameMapUtil.curMapState.isHeroArenaMap)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.HeroArenaOpenOrCloseMainWin));
            }
            else if (Cache.instance.heroArena.hasRewardCanTake())
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.HeroArenaOpenOrCloseMainWin));
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.HeroArenaOpenOrCloseEnterWin));
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            if (Cache.instance.heroArena.hasRewardCanTake())
            {
                HeroArenaIcon.instance.playEffect();
            }
            else
            {
                HeroArenaIcon.instance.stopEffect();
            }
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._leftTime.dispose();
            this._leftTime = null;
            return;
        }// end function

        public static function get instance() : HeroArenaIcon
        {
            if (!_instance)
            {
                _instance = new HeroArenaIcon(new ExceptionClass());
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}

class ExceptionClass extends Object
{

    function ExceptionClass()
    {
        return;
    }// end function

}

